<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <%@include file="../../common.jsp"%>

    <style>
        .layui-input{
            background: #c1b9ae;
        }
        .layui-textarea{
            background: #c1b9ae;
        }
    </style>
</head>
<body style="background: #e0dbd6">
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="number" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入用户密码" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

        $.ajax({
                'url': base_url + '/user/addUser.do',
                'data': data.field,
                'method': 'post',
                success: function () {
                    layer.alert("添加成功",function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        window.parent.location.reload();
                    });
                },
                error: function() {
                    layer.alert("请求异常");
                }
            });
            return false;
        });

    });

</script>
</body>
</html>